<%String nav="result"; %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.google.appengine.api.users.*" %>
<%
  UserService userService = UserServiceFactory.getUserService();
  User user = userService.getCurrentUser();
  String authURL = (user != null) ? userService.createLogoutURL(request.getRequestURI()): userService.createLoginURL(request.getRequestURI());
%><!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Show Minifier - Visual web page compressor</title>
    <link type="text/css" rel="stylesheet" href="/css/project.css" />
  </head>
  <body>
  <div class="page">
  <div class="head">
    <div class="signin">
      <% if (user != null) { %>
         <%= user.getEmail() %> | <a href="/settings">settings</a> | 
      <% } %>
      <a href="<%= authURL %>">
        <% if (user != null) { %>Log out<% } else  { %>Log in<% } %>
      </a>
    </div>
    <h1>
        Show Minifier
    </h1>
    <ul class="nav">
    	<li><a <% if(nav.equals("home")){%>class="selected" <%}%>href="/">Home</a>
        <li><a <% if(nav.equals("test")){%>class="selected" <%}%> href="/test">New Test</a>
        <li><a <% if(nav.equals("result")){%>class="selected" <%}%>href="/result">Test Result</a>
        <li><a href="http://code.google.com/p/showminifier">Download</a>
    	<!--li><a <% if(nav.equals("performance")){%>class="selected"<%}%> href="/performance">Performance</a-->
    	<!--li><a <% if(nav.equals("help")){%>class="selected"<%}%> href="/help">Help</a-->
        <li><a href="http://groups.google.com/group/showminifier">Forums</a>
    </ul>
    </div>
	<div class="body">
	<div class="resultList">
<%@ page import="java.text.*"%>
<%@ page import="javax.jdo.*"%>
<%@ page import="org.showminifier.web.*" %>
<%@ page import="java.util.*" %>
<%
Long keyId = null;
boolean found = false;
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
try{
	keyId = Long.parseLong(request.getParameter("key"));
}catch( NumberFormatException e){
}
PersistenceManager pm = PMF.get().getPersistenceManager();
ArrayList<PagePerformance> entries = null;
WebContent content = null;
try{			
	content = pm.getObjectById(WebContent.class,keyId);;
	found = true;
}catch(JDOObjectNotFoundException e){
}
if(!found){%>
	<div class="error">Some error occured while connecting database.Please wait for a moment.</div>
<% 
}else{
	entries = new ArrayList<PagePerformance>(content.getPerformance());
	String browser = "";
	if(entries == null || entries.isEmpty()){
%>
	<div class="error">No performance score with URL "<%= content.getUrl().getValue() %>".You should <a href="/evaluate?key=<%= keyId %>&reflow=true">evaluate it</a>.</div>
<%} else{
%>
	<table class="multi">
	<caption>Performance score 
	<thead><tr><th>Timestamp<th>Browser<th>Page parser performance<th>Network latency<th>Page reflow time
	<tfoot><tr><td rowspan="6"> <a href="/evaluate?key=<%= keyId %>&reflow=true">Evaluate</a>
<%
		for (PagePerformance entry : entries) {
	%>
	<% if(!browser.equalsIgnoreCase(entry.getBrowser())){
			browser = entry.getBrowser();
	%>
	<tbody>
	<% }%>
	<tr><td><%= sdf.format(entry.getRequestDate()) %>
	<td><%= entry.getBrowser() %> ( <%= entry.getVersion() %> )
	<td><%= entry.getOriginalPerformance() %>MS ( <%= entry.getMinifiedPerformance() %>MS Minified)
	<td><%= entry.getOriginalLatency() %>MS ( <%= entry.getMinifiedLatency() %>MS Minified)
	<td><%= entry.getOriginalReflowTime() < 1 ? "none" : entry.getOriginalReflowTime() + "MS" + "( " + entry.getMinifiedReflowTime() + "MS  Minified)" %> 
<%	
		}
 %>
	  </table>
<%       
 }
}%> 
</div>
</div>
<%@ include file="include/foot.jsp"%>
</div>
